# 配置加载工具
import yaml
import os
from typing import Dict, Any


class ConfigLoader:
    """配置文件加载器"""

    def __init__(self, config_dir: str = "config"):
        self.config_dir = config_dir
        self._configs = {}

    def load_config(self, config_name: str) -> Dict[Any, Any]:
        """
        加载指定的配置文件
        Args:
            config_name: 配置文件名(不含扩展名)
        Returns:
            配置字典
        """
        if config_name in self._configs:
            return self._configs[config_name]

        config_path = os.path.join(self.config_dir, f"{config_name}.yaml")

        if not os.path.exists(config_path):
            raise FileNotFoundError(f"配置文件不存在: {config_path}")

        with open(config_path, 'r', encoding='utf-8') as file:
            config = yaml.safe_load(file)
            self._configs[config_name] = config
            return config

    def get_app_config(self) -> Dict[Any, Any]:
        """获取应用配置"""
        return self.load_config('app_config')

    def get_model_config(self) -> Dict[Any, Any]:
        """获取模型配置"""
        return self.load_config('model_config')

    def get_redis_config(self) -> Dict[Any, Any]:
        """获取Redis配置"""
        return self.load_config('redis_config')
